﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.IO;


namespace TravelLink.Common {
    public class Photo {
        public int Size { get; set; }

        public string RelativePath { get; set; }

        public string PhysicalPath { get; set; }

        public string Extension { get; set; }

        public string FileName { get; set; }


    }

    public class SitePhoto {

        public Photo OriPhoto { get; set; }

        public Photo ThumbnailPhoto { get; set; }


    }


    public class SiteFile {

        public string PhysicalPath { get; set; }

        public string RelativePath { get; set; }

        public string FileName { get; set; }

        public string Extension { get; set; }

        public string Ico { get; set; }

        public int Size { get; set; }
    }

    public class PhotoManager {

        const string UploadDirectory = "~/photos/";
        const string UploadThumbnailDirectory = "~/photos/ThumbnailPhoto/";
        const int ThumbnailSize = 100;

        const string UploadFileDirectory = "~/photos/";


        public static SiteFile BuildUploadfile(string sessionId, string uploadFile) {
            string extension = Path.GetExtension(uploadFile);
            string photoName = DateTime.Now.ToString("yyyyMMddhhmmss") + extension;
            string oriRelative = "/photos/" + photoName;

            string oriPhoto = HttpContext.Current.Server.MapPath(UploadFileDirectory) + photoName;


            SiteFile file = new SiteFile();

            file.Extension = extension;
            file.FileName = photoName;
            file.PhysicalPath = oriPhoto;
            file.RelativePath = oriRelative;

            //    CacheProxy.Update(file, "HKProject_Video_File" + sessionId);
            return file;
        }


        public static SitePhoto BuildTemplaitePath(string sessionid, string uploadFilename) {
            string extension = Path.GetExtension(uploadFilename);
            string photoName = DateTime.Now.ToString("yyyyMMddhhmmss") + extension;
            string oriRelative = "/photos/" + photoName;
            string thumbnailRelative = "/photos/ThumbnailPhoto/" + photoName;
            string oriPhoto = HttpContext.Current.Server.MapPath(UploadDirectory) + photoName;
            string thumbnail = HttpContext.Current.Server.MapPath(UploadThumbnailDirectory) + photoName;

            SitePhoto sitePhoto = new SitePhoto();

            sitePhoto.OriPhoto = new Photo();
            sitePhoto.OriPhoto.Extension = extension;
            sitePhoto.OriPhoto.FileName = photoName;
            sitePhoto.OriPhoto.PhysicalPath = oriPhoto;
            sitePhoto.OriPhoto.RelativePath = oriRelative;


            sitePhoto.ThumbnailPhoto = new Photo();
            sitePhoto.ThumbnailPhoto.Extension = extension;
            sitePhoto.ThumbnailPhoto.FileName = photoName;
            sitePhoto.ThumbnailPhoto.PhysicalPath = thumbnail;
            sitePhoto.ThumbnailPhoto.RelativePath = thumbnailRelative;


            //   CacheProxy.Update(sitePhoto, "HKProject_Video_Photo" + sessionid);
            return sitePhoto;
        }


        //public static void UpdateMemory(string sessionId, SitePhoto sitePhoto) {
        //    CacheProxy.Update(sitePhoto, "HKProject_Video_Photo" + sessionId);
        //}

        //public static SitePhoto GetMemory(string sessionid) {
        //    return CacheProxy.GetMemory<SitePhoto>("HKProject_Video_Photo" + sessionid);
        //}

        //public static void EmptyPhoto(string sessionid) {
        //    CacheProxy.DeleteMemory("HKProject_Video_Photo" + sessionid);
        //}



        //public static void UpdateMemory(string sessionId, SiteFile sitePhoto) {
        //    CacheProxy.Update(sitePhoto, "HKProject_Video_File" + sessionId);
        //}

        //public static SiteFile GetMemoryFile(string sessionid) {
        //    return CacheProxy.GetMemory<SiteFile>("HKProject_Video_File" + sessionid);
        //}

        //public static void EmptyFile(string sessionid) {
        //    CacheProxy.DeleteMemory("HKProject_Video_File" + sessionid);
        //}

    }
}
